package com.example.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.pojo.controlPlanNewPojo;
import com.example.pojo.controlPlanPojo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * ClassName:ddm
 * Description:
 *
 * @Author 赵永峰
 * @Create 2025/6/30 16:11
 * @Version 1.0
 */
@Mapper
public interface controlPlanNewMapp {
    //对控制计划插入多行数据
    @DS("newMscLowCodeFormal")
    void insertMultiLine(List<controlPlanNewPojo> pojos);
    //辅助函数：根据两个字符串类型的字段，查询分别等于某一值的数据(控制计划的表）
    @DS("newMscLowCodeFormal")
    @Select("select * from ddm_control_plan where ${firstFieldName}=#{firstFieldVal} and ${secondFieldName}=#{secondFieldVal}")
    List<controlPlanNewPojo> queryTwoField(String firstFieldName, String firstFieldVal, String secondFieldName, String secondFieldVal);

    @DS("newMscLowCodeFormal")
    @Insert("INSERT INTO ddm_control_plan " +
            "(id, create_time, update_time, " +
            "creator, process_status, sys_update_user, " +
            "sys_audit_user, sys_audit_time, sys_deleted, " +
            "process_number, process_number_english, process_number_russian, " +
            "device, device_english, device_russian, " +
            "operation, operation_english, operation_russian, " +
            "number_order, product, product_english, " +
            "product_russian, process_use, process_use_english, " +
            "process_use_russian, characteristic, specification, " +
            "specification_english, specification_russian, measure, " +
            "measure_english, measure_russian, capacity, " +
            "capacity_english, capacity_russian, frequency, " +
            "frequency_english, frequency_russian, method, " +
            "method_english, method_russian, department, " +
            "department_english, department_russian, reaction, " +
            "drawing, op, workshop, " +
            "order_number, control_testing) " +
            "VALUES (" +
            "#{id}, #{create_time}, #{update_time}, " +
            "#{creator}, #{process_status}, #{sys_update_user}, " +
            "#{sys_audit_user}, #{sys_audit_time}, #{sys_deleted}, " +
            "#{process_number}, #{process_number_english}, #{process_number_russian}, " +
            "#{device}, #{device_english}, #{device_russian}, " +
            "#{operation}, #{operation_english}, #{operation_russian}, " +
            "#{number_order}, #{product}, #{product_english}, " +
            "#{product_russian}, #{process_use}, #{process_use_english}, " +
            "#{process_use_russian}, #{characteristic}, #{specification}, " +
            "#{specification_english}, #{specification_russian}, #{measure}, " +
            "#{measure_english}, #{measure_russian}, #{capacity}, " +
            "#{capacity_english}, #{capacity_russian}, #{frequency}, " +
            "#{frequency_english}, #{frequency_russian}, #{method}, " +
            "#{method_english}, #{method_russian}, #{department}, " +
            "#{department_english}, #{department_russian}, #{reaction}, " +
            "#{drawing}, #{op}, #{workshop}, " +
            "#{order_number}, #{control_testing} )")
    void insertOne(controlPlanNewPojo pojo);

    @DS("newMscLowCodeFormal")
    //更新哪些字段的数据
    @Update("update ddm_control_plan " +
            "set " +
            "create_time=#{create_time}," +
            "update_time=#{update_time}," +
            "creator=#{creator}," +
            "process_status=#{process_status}," +
            "sys_update_user=#{sys_update_user}," +
            "sys_audit_user=#{sys_audit_user}," +
            "sys_audit_time=#{sys_audit_time}," +
            "sys_deleted=#{sys_deleted}," +
            "process_number=#{process_number}," +
            "process_number_english=#{process_number_english}," +
            "process_number_russian=#{process_number_russian}," +
            "device=#{device}," +
            "device_english=#{device_english}," +
            "device_russian=#{device_russian}," +
            "operation=#{operation}," +
            "operation_english=#{operation_english}," +
            "operation_russian=#{operation_russian}," +
            "number_order=#{number_order}," +
            "product=#{product}," +
            "product_english=#{product_english}," +
            "product_russian=#{product_russian}," +
            "process_use=#{process_use}," +
            "process_use_english=#{process_use_english}," +
            "process_use_russian=#{process_use_russian}," +
            "characteristic=#{characteristic}," +
            "specification=#{specification}," +
            "specification_english=#{specification_english}," +
            "specification_russian=#{specification_russian}," +
            "measure=#{measure}," +
            "measure_english=#{measure_english}," +
            "measure_russian=#{measure_russian}," +
            "capacity=#{capacity}," +
            "capacity_english=#{capacity_english}," +
            "capacity_russian=#{capacity_russian}," +
            "frequency=#{frequency}," +
            "frequency_english=#{frequency_english}," +
            "frequency_russian=#{frequency_russian}," +
            "method=#{method}," +
            "method_english=#{method_english}," +
            "method_russian=#{method_russian}," +
            "department=#{department}," +
            "department_english=#{department_english}," +
            "department_russian=#{department_russian}," +
            "reaction=#{reaction}," +
            "drawing=#{drawing}," +
            "op=#{op}," +
            "workshop=#{workshop}," +
            "order_number=#{order_number}," +
            "control_testing=#{control_testing}"+
            //明确修改的是某一行，而不是将所有行全部修改（如果不写的话会默认修改所有行数据）
            " where id=#{id}")
    void editOneById(controlPlanNewPojo pojo);

    //根据三个字段查询所有数据：现在用在了根据工序号、发动机图号、车间名称进行查询。利用的是模糊查询。
    @DS("newMscLowCodeFormal")
    @Select("select * from ddm_control_plan where " +
            "${firstFieldName} like concat('%',#{firstFieldVal},'%') " +
            "and ${secondFieldName} like concat('%',#{secondFieldVal},'%') " +
            "and ${thirdFieldName}=#{thirdFieldVal} " +
            "and sys_deleted=0 " +
            "order by order_number ASC")
    List<controlPlanNewPojo> queryThreeField(String firstFieldName, String firstFieldVal, String secondFieldName, String secondFieldVal, String thirdFieldName, String thirdFieldVal);

    //根据id查询一行
    @DS("newMscLowCodeFormal")
    @Select("select * from ddm_control_plan " +
            "where id=#{id}")
    List<controlPlanNewPojo> queryOneById(String id);
}
